// Copyright Dotware Technologies 2005. Author Hadi Asghari.
// DBaseRecordSet.h : Declaration of the CDBaseRecordSet

#pragma once
#include "resource.h"       // main symbols

#include "dwDbfCom.h"
#include <DBFRecordset.h>


// CDBaseRecordSet

class ATL_NO_VTABLE CDBaseRecordSet : 
	public CComObjectRootEx<CComSingleThreadModel>,
	public CComCoClass<CDBaseRecordSet, &CLSID_DBaseRecordSet>,
	public IDispatchImpl<IDBaseRecordSet, &IID_IDBaseRecordSet, &LIBID_dwDbfComLib, /*wMajor =*/ 1, /*wMinor =*/ 0>
{
public:
	CDBaseRecordSet()
	{
		DWORD lcid = MAKELCID(0x429, SORT_DEFAULT); // Farsi
		::SetThreadLocale(lcid); // set "our" thread locale
	}

DECLARE_REGISTRY_RESOURCEID(IDR_DBASERECORDSET)


BEGIN_COM_MAP(CDBaseRecordSet)
	COM_INTERFACE_ENTRY(IDBaseRecordSet)
	COM_INTERFACE_ENTRY(IDispatch)
END_COM_MAP()


	DECLARE_PROTECT_FINAL_CONSTRUCT()

	HRESULT FinalConstruct()
	{
		return S_OK;
	}
	
	void FinalRelease() 
	{
	}

private:
	CDBFRecordset m_Set;
public:

	STDMETHOD(Open)(BSTR filename);
	STDMETHOD(IsEof)(BYTE* retVal);
	STDMETHOD(GetFieldCount)(SHORT* retVal);
	STDMETHOD(MoveNext)(void);
	STDMETHOD(Close)(void);
	STDMETHOD(GetFieldValueS)(BSTR fieldname, VARIANT* retVal);
	STDMETHOD(GetFieldValueI)(SHORT index, VARIANT* retVal);
	STDMETHOD(GetFieldInfo)(SHORT index, BSTR* name, CHAR* type, SHORT* length, SHORT* decimal);
	STDMETHOD(GetRecordCount)(ULONG* retVal);
	STDMETHOD(CreateTable)(BSTR fileName, BYTE* retVal);
	STDMETHOD(AddFieldC)(BSTR fieldName, SHORT fieldLength);
	STDMETHOD(AddFieldN)(BSTR fieldName, BYTE fieldLength, BYTE fieldDecimal);
	STDMETHOD(UpdateTable)(void);
	STDMETHOD(AddFieldL)(BSTR fieldName);
	STDMETHOD(SetFieldValue)(BSTR fieldName, VARIANT fieldValue);
	STDMETHOD(Edit)(void);
	STDMETHOD(Update)(void);
	STDMETHOD(AddNew)(void);
	STDMETHOD(Delete)(void);
	STDMETHOD(MoveLast)(void);
	STDMETHOD(MoveFirst)(void);
	STDMETHOD(MovePrev)(void);
	STDMETHOD(IsOpen)(BYTE* retVal);
	STDMETHOD(FindFirst)(BSTR filter, BYTE* retVal);
	STDMETHOD(FindNext)(BSTR filter, BYTE* retVal);
	STDMETHOD(FindPrev)(BSTR filter, BYTE* retVal);
	STDMETHOD(FindLast)(BSTR filter, BYTE* retVal);
	STDMETHOD(GetRecord)(VARIANT ** retVal);
	STDMETHOD(FreeRecord)(LONG ptr);
	STDMETHOD(get_DbfId)(BYTE* pVal);
	STDMETHOD(get_DbfRecordSize)(ULONG* pVal);
	STDMETHOD(get_DbfCodePage)(BYTE* pVal);
	STDMETHOD(get_LastUpdate)(DATE* pVal);
	STDMETHOD(get_Position)(LONG* pVal);
	STDMETHOD(put_Position)(LONG newVal);
	STDMETHOD(get_TableFlag)(BYTE* pVal);
};

OBJECT_ENTRY_AUTO(__uuidof(DBaseRecordSet), CDBaseRecordSet)
